package com.level.game;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

import com.badlogic.gdx.math.Vector2;
import com.engine.game.GameFabric;
import com.engine.game.GameState;


public abstract class Level {

	private ArrayList<Instruction> setOfInstructions;
	
	protected String physicsWorld;  // точное название физического мира
	protected String contactListener; // точное название конкретного ContactListener
	
	
	public Level(){
		
		this.setOfInstructions = new ArrayList<Instruction>();
		
		this.setPhysicsWorldDefinition();
		this.setContactListenerDefinition();
		
		
		this.fillWithInstructions();
		
	}
	
	public abstract void setPhysicsWorldDefinition();
	public abstract void setContactListenerDefinition();
	public abstract void fillWithInstructions();
	
	
	protected void addInstruction(Instruction instruction){
		this.setOfInstructions.add(instruction);
	}
	
	// здесь используем фабрику
	public void load(GameState state) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException{     
		
		
		state.setPhysicsWorld(GameFabric.createPhysicsWorld(this.physicsWorld, this.contactListener));
		
		for(Instruction inst : this.setOfInstructions){
			
			state.addStageToRenderer(GameFabric.createStage(inst.getStageInfo()));
			
			for(GameObjectInfo inf : inst.getGameObjectsInfo()){
				state.addGameObject(GameFabric.createGameObject(state, inf));
			}
		}
		
	}
	
	public abstract Vector2 getWorldMax();
	
	public void dispose(){
		this.setOfInstructions.clear();
		this.setOfInstructions = null;
	}
	
}
